#include "stdafx.h"
#include "CritSection.h"


CritSectionLocker::CritSectionLocker()
{
	::InitializeCriticalSectionAndSpinCount(&critSection, 500);
}

CritSectionLocker::~CritSectionLocker()
{
	::DeleteCriticalSection(&critSection);
}

void CritSectionLocker::lock()
{
	::EnterCriticalSection(&critSection);
}

void CritSectionLocker::unlock()
{
	::LeaveCriticalSection(&critSection);
}


ScoupedLocker::ScoupedLocker(const CritSectionLocker &critSectionLocker) : locker(const_cast<CritSectionLocker&>(critSectionLocker))
{
	locker.lock();
}

ScoupedLocker::~ScoupedLocker()
{
	locker.unlock();
}
